| Conditions | 2 | 
| Total Lines | 58 | 
| Code Lines | 53 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import { TreeStructure } from './details-mappers'; | 
            ||
| 27 | |||
| 28 | export function createDiagram(  | 
            ||
| 29 | tree: HierarchyPointNode<TreeStructure>,  | 
            ||
| 30 | containerWidth: number,  | 
            ||
| 31 | containerHeight: number,  | 
            ||
| 32 | rootNodeYOffset: number,  | 
            ||
| 33 | drawToLeft: boolean = false  | 
            ||
| 34 | ) { | 
            ||
| 35 |     if (!tree.children || !tree.children.length) { | 
            ||
| 36 | return null;  | 
            ||
| 37 | }  | 
            ||
| 38 | |||
| 39 | const diagramWidth = containerWidth / 2;  | 
            ||
| 40 | const diagramXOffset = -diagramWidth / 8;  | 
            ||
| 41 | const diagramYOffset = -containerHeight / 2;  | 
            ||
| 42 | |||
| 43 |     const svg = create('svg').attr('viewBox', `${diagramXOffset} ${diagramYOffset + rootNodeYOffset} ${diagramWidth} ${containerHeight}`); | 
            ||
| 44 | |||
| 45 | const g = svg  | 
            ||
| 46 |         .append('g') | 
            ||
| 47 |         .attr('font-size', 15) | 
            ||
| 48 |         .attr('transform', transformDiagramElement(0, rootNodeYOffset, drawToLeft)); | 
            ||
| 49 | |||
| 50 |     g.append('g') | 
            ||
| 51 |         .attr('fill', 'none') | 
            ||
| 52 |         .attr('stroke', Colors.ANCHOR_BLUE) | 
            ||
| 53 |         .attr('stroke-width', 2) | 
            ||
| 54 |         .selectAll('path') | 
            ||
| 55 | .data(tree.links())  | 
            ||
| 56 |         .join('path') | 
            ||
| 57 | .attr(  | 
            ||
| 58 | 'd',  | 
            ||
| 59 | linkHorizontal<HierarchyPointLink<TreeStructure>, HierarchyPointNode<TreeStructure>>()  | 
            ||
| 60 | .x(d => d.y)  | 
            ||
| 61 | .y(d => d.x)  | 
            ||
| 62 | );  | 
            ||
| 63 | |||
| 64 | const node = g  | 
            ||
| 65 |         .append('g') | 
            ||
| 66 |         .attr('stroke-linejoin', 'round') | 
            ||
| 67 |         .attr('stroke-width', 3) | 
            ||
| 68 |         .selectAll('g') | 
            ||
| 69 | .data(tree.descendants())  | 
            ||
| 70 |         .join('g') | 
            ||
| 71 |         .attr('transform', d => transformDiagramElement(d.y, d.x, drawToLeft)); | 
            ||
| 72 | |||
| 73 |     node.append('text') | 
            ||
| 74 |         .attr('dy', '0.31em') | 
            ||
| 75 |         .attr('x', 0) | 
            ||
| 76 |         .attr('text-anchor', 'middle') | 
            ||
| 77 |         .style('background-color', '#ffffff') | 
            ||
| 78 | .text(node => node.data.name)  | 
            ||
| 79 | .clone(true)  | 
            ||
| 80 | .lower()  | 
            ||
| 81 |         .attr('stroke-width', 4) | 
            ||
| 82 |         .attr('stroke', 'white'); | 
            ||
| 83 | |||
| 84 | return svg;  | 
            ||
| 85 | }  | 
            ||
| 90 |